package com.harboursoftware.xstorage.web;

import java.util.Date;
import java.util.Map;

import com.google.common.collect.Multimap;
import com.harboursoftware.xstorage.XStorageException;
import com.harboursoftware.xstorage.results.ErrorResult;
import com.harboursoftware.xstorage.results.ErrorResult.Type;

class ExpireChecker {

    /**
     * 检测当前的请求是否已过期
     * 在发生异常的情况下，抛出的XStorageException可以通过getErrorResult()方法回去具体的错误Result。
     * @param method
     * @param headers
     * @param parameters
     * @throws XStorageException 如果请求过期
     */
    public static void expireCheck(String method, Multimap<String, String> headers, Map<String, String> parameters)
        throws XStorageException {
        String expiresString = null;
        //Query String Authentication
        if("GET".equals(method) && parameters.containsKey("Signature")) {
            expiresString = parameters.get("Expires");
            if(expiresString == null) {
                ErrorResult errorResult = ErrorResult.create(Type.ACCESS_DENIED);
                errorResult.setMessage("Query-string authentication requires the Signature, Expires and AWSAccessKeyId parameters");
                throw new XStorageException(errorResult, "Query-string authentication requires the Expires parameters");
            }
          
        } else if("POST".equals(method)) {
            //see PostObjectRequestParser#parsePostRequestParameters
            expiresString = parameters.get("Expires");
        }
        
      //当heades中Date  x-ams-data 等时间参数格式不一致的时候，应该如何处理
        Date now = new Date();
        Date expires = null;
        
        
    }

}
